export default {
  data () {
    return {
      moduleType: ['BP', 'RP']
    }
  },
  computed: {
    columns() {
      const columns = [
        {
          // align: 'center',
          title: '序号',
          width: 60,
          customRender(t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          // align: 'center',
          title: '模块',
          dataIndex: 'bizModuleName',
          key: 'bizModuleName',
          width: 100,
          ellipsis: true,
        },
        {
          // align: 'center',
          title: '申请名称',
          dataIndex: 'applicationName',
          key: 'applicationName',
          width: 200,
          ellipsis: true,
          scopedSlots: {
            customRender: 'applicationName',
          },
        },
        {
          // align: 'center',
          title: '当前状态',
          dataIndex: 'currStatus',
          key: 'currStatus',
          width: 80,
          ellipsis: true,
          customRender: (text) => this.stateOptions[text]
        },
        {
          // align: 'center',
          title: '当前处理人',
          dataIndex: 'lastNodeSubmitter',
          key: 'lastNodeSubmitter',
          width: 80,
          ellipsis: true,
        },
        // {
          // align: 'center',
        //   title: '上个节点提交时间',
        //   dataIndex: 'lastNodeTime',
        //   key: 'lastNodeTime',
        //   width: 120,
        //   ellipsis: true,
        // },
        {
          // align: 'center',
          title: '申请人',
          dataIndex: 'applicantName',
          key: 'applicantName',
          width: 80,
          ellipsis: true,
        },
        {
          // align: 'center',
          title: '申请时间',
          dataIndex: 'applicantTime',
          key: 'applicantTime',
          width: 80,
          ellipsis: true,
        },
      ];
      return columns;
    },
    bizModuleGroup() {
      return {
        BP: '/plan-bp',
        RP: '/plan-rp',
        M3: '/m3',
        M9: '/m9',
        PC: '/price-change',
        // leads: 'leads',
        CUSTOMER_CREATE: '/customer-creation',
        VI: '/matters-fllow',
        // biz: '/business-follow'
      }
      // return [
      //   {
      //     bizModule: 'BP',
      //     path: '/plan-bp'
      //   },
      //   {
      //     bizModule: 'RP',
      //     path: '/plan-rp'
      //   },
      //   {
      //     bizModule: 'M3',
      //     path: '/forecast-m3'
      //   },
      //   {
      //     bizModule: 'M9',
      //     path: '/forecast-m9'
      //   },
      //   {
      //     bizModule: 'PC',
      //     path: '/price-change'
      //   },
      //   {
      //     bizModule: 'leads',
      //     path: '/clue-creation'
      //   },
      // ]
    },
    stateOptions() {
      return this.$store.state.dictionary.dict['state'] || {};
    },
  },
  methods: {
    pathFn(record) {
      const leads = {
        create: '/clue-creation',
        transfer: '/clue-transfer',
        transBiz: '/clue-business'
      }
      const business = {
        business: '/business-follow',
        business_trans: '/business-transfer',
      }
      if (record.bizModule === 'leads') {
        return leads[record.snapshootType]
      } else if (record.bizModule === 'biz') {
        return business[record.snapshootType]
      } else {
        return this.bizModuleGroup[record.bizModule]
      }
    },
    idFn(record) {
      let id = ''
      if (record.bizModule === 'biz' && record.snapshootType === 'business') {
        id = 'opportunityNo'
      } else if (record.bizModule === 'biz' && record.snapshootType === 'business_trans') {
        id = 'transferNo'
      } else if (record.bizModule === 'leads' && record.snapshootType === 'create') {
        id = 'leadsNo'
      } else if (record.bizModule === 'leads' && record.snapshootType === 'transfer') {
        id = 'auditNo'
      } else if (record.bizModule === 'leads' && record.snapshootType === 'transBiz') {
        id = 'auditNo'
      } else {
        id = 'id'
      }
      return id;
    },
    handleRouterClick(record) {
      console.log(this.pathFn(record))
      // 仅路由跳转
      let node = record.bizModule === 'biz' ? 'stage' : this.moduleType.includes(record.bizModule) ? 'node' : 'nodeCode';
      let id = this.idFn(record);
      this.$router.push({
        path: this.pathFn(record),
        query: {
          [id]: (record.bizModule === 'leads' || record.bizModule === 'biz') ? record.no : record.bizModuleId,
          [node]: record.nodeCode || '',
          processId: record.processId,
          path: '1'
        },
      });
    },
  }
};
